package de.hs.rm.UJAdapter.factory;

import java.util.Dictionary;
import java.util.Hashtable;

import javax.management.MBeanServerDelegateMBean;


import org.osgi.framework.BundleContext;
import org.osgi.service.upnp.UPnPDevice;

import de.hs.rm.UJAdapter.impl.UJDevice;

public class UJDeviceFactory {

	public static UJDevice createRootDevice(BundleContext bundleContext, MBeanServerDelegateMBean delegateProxyMBean, String UDN, String[] childrenUDN)
	{
		UJDevice agentDevice = new UJDevice();
		Dictionary props = new Hashtable(14);
		if(childrenUDN != null)
			props.put(UPnPDevice.CHILDREN_UDN, childrenUDN);
			
		props.put(UPnPDevice.DEVICE_CATEGORY, 
	              new String[]{UPnPDevice.DEVICE_CATEGORY});
	    props.put(UPnPDevice.UDN, UDN);    
	    props.put(UPnPDevice.TYPE, "urn:hs-rm-de:device:MBeanDevice:1");
	    props.put(UPnPDevice.FRIENDLY_NAME, delegateProxyMBean.getMBeanServerId());
	    props.put(UPnPDevice.MANUFACTURER, delegateProxyMBean.getImplementationVendor());
	    props.put(UPnPDevice.MANUFACTURER_URL, "http://www.oracle.com");
	    props.put(UPnPDevice.MODEL_DESCRIPTION, delegateProxyMBean.getImplementationName());
	    props.put(UPnPDevice.MODEL_NAME, delegateProxyMBean.getSpecificationName());
	    props.put(UPnPDevice.MODEL_NUMBER, "1");
	    props.put(UPnPDevice.MODEL_URL, "http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html");
	    props.put(UPnPDevice.UPC, "12345");
	    props.put(UPnPDevice.SERIAL_NUMBER, "123");
	    props.put(UPnPDevice.UPNP_EXPORT, "Yes");
	    props.put(UPnPDevice.PRESENTATION_URL, "");
	    agentDevice.setDescriptions(props);
	    
	    agentDevice.setBundleContext(bundleContext);
	        
		return agentDevice;
	}
	
	public static UJDevice createSubDevice(BundleContext bundleContext, MBeanServerDelegateMBean delegateProxyMBean, String UDN, String parentUDN)
	{
		UJDevice agentDevice = new UJDevice();
		Dictionary props = new Hashtable(14);
		props.put(UPnPDevice.PARENT_UDN, parentUDN);
					
		props.put(UPnPDevice.DEVICE_CATEGORY, 
	              new String[]{UPnPDevice.DEVICE_CATEGORY});
	    props.put(UPnPDevice.UDN, UDN);     
	    props.put(UPnPDevice.TYPE, "urn:hs-rm-de:device:MBeanDevice:1");
	    props.put(UPnPDevice.FRIENDLY_NAME, delegateProxyMBean.getMBeanServerId());
	    props.put(UPnPDevice.MANUFACTURER, delegateProxyMBean.getImplementationVendor());
	    props.put(UPnPDevice.MANUFACTURER_URL, "http://www.oracle.com");
	    props.put(UPnPDevice.MODEL_DESCRIPTION, delegateProxyMBean.getImplementationName());
	    props.put(UPnPDevice.MODEL_NAME, delegateProxyMBean.getSpecificationName());
	    props.put(UPnPDevice.MODEL_NUMBER, "1");
	    props.put(UPnPDevice.MODEL_URL, "http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html");
	    props.put(UPnPDevice.UPC, "12345");
	    props.put(UPnPDevice.SERIAL_NUMBER, "123");
	    props.put(UPnPDevice.UPNP_EXPORT, "Yes");
	    props.put(UPnPDevice.PRESENTATION_URL, "");
	    agentDevice.setDescriptions(props);
	    
	    agentDevice.setBundleContext(bundleContext);
	        
		return agentDevice;
	}
}
